﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text;
using RxjhServer.HelperTools;

namespace RxjhServer.DbClss
{
	public class RxjhClass
	{
		private static ItmesIDClass ItmeId = new ItmesIDClass();

		public static string GetRandomString()
		{
			byte[] array = new byte[4];
			new RNGCryptoServiceProvider().GetBytes(array);
			Random random = new Random(BitConverter.ToInt32(array, 0));
			string text = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			return text.Substring(random.Next(0, text.Length - 1), 1);
		}

		public static string md5(string strmm)
		{
			MD5 mD = new MD5CryptoServiceProvider();
			byte[] value = mD.ComputeHash(Encoding.ASCII.GetBytes(strmm));
			return BitConverter.ToString(value).Replace("-", "").ToLower();
		}

		public static long GetDBItmeId()
		{
			return RxjhClass.ItmeId.AcquireBuffer();
		}
        public static DataTable 得到势力战数据()
        {
            SqlParameter[] prams = new SqlParameter[]
            {
                SqlDBA.MakeInParam("@id", SqlDbType.Int, 4, 0)
            };
            DataTable dataTable = SqlDBA.RunProcc(new SqlConnection(DBA.getstrConnection(null)), "XWWL_LOAD_EVENTTOP", prams);
            if (dataTable != null)
            {
                if (dataTable.Rows.Count > 0)
                {
                    return dataTable;
                }
                dataTable.Dispose();
            }
            return null;
        }
        public static void 保存势力战数据(EventTopClass EventTop)
        {
            SqlParameter[] prams = new SqlParameter[]
            {
                SqlDBA.MakeInParam("@name", SqlDbType.NVarChar, 30, EventTop.人物名),
                SqlDBA.MakeInParam("@bpname", SqlDbType.NVarChar, 30, EventTop.帮派),
                SqlDBA.MakeInParam("@zx", SqlDbType.NVarChar, 30, EventTop.势力),
                SqlDBA.MakeInParam("@level", SqlDbType.Int, 4, EventTop.等级),
                SqlDBA.MakeInParam("@killnum", SqlDbType.Int, 4, EventTop.杀人数),
                SqlDBA.MakeInParam("@deathnum", SqlDbType.Int, 4, EventTop.死亡数),
                //SqlDBA.MakeInParam("@fq", SqlDbType.NVarChar, 30, EventTop.分区),
                //SqlDBA.MakeInParam("@joblevel", SqlDbType.Int, 4, EventTop.转职)
            };
            SqlDBA.RunProc(new SqlConnection(DBA.getstrConnection(null)), "XWWL_INSERT_EVENTTOP_LOGS", prams);
        }
        public static void 变更门服(int 帮派id, int 门服字, int 门服颜色)
		{
			string sqlCommand = string.Format("UPDATE TBL_帮派数据 SET 门服字={1},门服颜色={2} WHERE ID='{0}'", 帮派id, 门服字, 门服颜色);
			DBA.ExeSqlCommand(sqlCommand);
		}

		public static void msglog(string userid, string username, string tousername, string msg, int msgType)
		{
			string sqlCommand = string.Format("INSERT INTO MsgLog (userid,username,ToUserName,msg,msgType) VALUES ('{0}','{1}','{2}','{3}',{4})", new object[]
			{
				userid,
				username,
				tousername,
				msg,
				msgType
			});
			DBA.ExeSqlCommand(sqlCommand);
		}

		public static void 百宝记录(string UserId, string UserName, double 物品ID, string 物品名, int 物品数量, int 元宝数)
		{
			string sqlCommand = string.Format("INSERT INTO 百宝记录 (UserId,UserName,物品ID,物品名,物品数量,元宝数) VALUES ('{0}','{1}','{2}','{3}',{4},{5})", new object[]
			{
				UserId,
				UserName,
				物品ID,
				物品名,
				物品数量,
				元宝数
			});
			DBA.ExeSqlCommand(sqlCommand);
		}

		public static void 登陆记录(string UserId, string UserName, string UserIp, string 类型)
		{
			if (World.登陆记录 == 1)
			{
				string sql = string.Format("INSERT INTO 登陆记录 (UserId,UserName,UserIp,类型) VALUES (@UserId,@UserName,@UserIp,@类型)", new object[0]);
				SqlParameter[] prams = new SqlParameter[]
				{
					SqlDBA.MakeInParam("@UserId", SqlDbType.VarChar, 30, UserId),
					SqlDBA.MakeInParam("@UserName", SqlDbType.VarChar, 30, UserName),
					SqlDBA.MakeInParam("@UserIp", SqlDbType.VarChar, 30, UserIp),
					SqlDBA.MakeInParam("@类型", SqlDbType.VarChar, 30, 类型)
				};
				DbPoolClass dbPoolClass = new DbPoolClass();
				dbPoolClass.Conn = DBA.getstrConnection(null);
				dbPoolClass.Prams = prams;
				dbPoolClass.Sql = sql;
				dbPoolClass.Type = 1;
				World.SqlPool.Enqueue(dbPoolClass);
			}
		}

		public static void 掉落记录(string UserId, string UserName, string 线路, double 全局ID, string 物品, string 掉落源, string 类型)
		{
			if (World.记录掉落)
			{
				string sql = string.Format("INSERT INTO 掉落记录 (UserId,UserName,线路,全局ID,物品,掉落源,类型) VALUES (@UserId,@UserName,@线路,@全局ID,@物品,@掉落源,@类型)", new object[0]);
				SqlParameter[] prams = new SqlParameter[]
				{
					SqlDBA.MakeInParam("@UserId", SqlDbType.VarChar, 30, UserId),
					SqlDBA.MakeInParam("@UserName", SqlDbType.VarChar, 30, UserName),
					SqlDBA.MakeInParam("@线路", SqlDbType.VarChar, 30, 线路),
					SqlDBA.MakeInParam("@全局ID", SqlDbType.VarChar, 30, 全局ID),
					SqlDBA.MakeInParam("@物品", SqlDbType.VarChar, 30, 物品),
					SqlDBA.MakeInParam("@掉落源", SqlDbType.VarChar, 30, 掉落源),
					SqlDBA.MakeInParam("@类型", SqlDbType.VarChar, 30, 类型)
				};
				DbPoolClass dbPoolClass = new DbPoolClass();
				dbPoolClass.Conn = DBA.getstrConnection(null);
				dbPoolClass.Prams = prams;
				dbPoolClass.Sql = sql;
				dbPoolClass.Type = 1;
				World.SqlPool.Enqueue(dbPoolClass);
			}
		}

		public static DataTable get首爆记录表(int 武器ID)
		{
			DataTable dBToDataTable = DBA.GetDBToDataTable(string.Format("select * from [首爆记录表] where 武器ID=@武器ID  order by  newDate"), new SqlParameter[1]
			{
				SqlDBA.MakeInParam("@武器ID", SqlDbType.Int, 0, 武器ID)
			});
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static void set首爆记录表(string UserId, string UserName, int wuqiID, string 武器名字)
		{
			string sql = string.Format("insert into[首爆记录表](Userid, UserName,  武器ID, 武器名字) VALUES(@Userid,@UserName,@武器ID,@武器名字)");
			SqlParameter[] prams = new SqlParameter[4]
			{
					SqlDBA.MakeInParam("@UserId", SqlDbType.VarChar, 30, UserId),
					SqlDBA.MakeInParam("@UserName", SqlDbType.VarChar, 30, UserName),
					SqlDBA.MakeInParam("@武器ID", SqlDbType.Int, 0, wuqiID),
					SqlDBA.MakeInParam("@武器名字", SqlDbType.VarChar, 200, 武器名字)
			};
			World.SqlPool.Enqueue(new DbPoolClass
			{
				Conn = DBA.getstrConnection(null),
				Prams = prams,
				Sql = sql,
				Type = 1
			});

		}

		public static void 物品记录(string UserId, string UserName, string ToUserId, string ToUserName, double 全局ID, int 物品ID, string 物品名, int 物品数量, string 物品属性, int 钱数, string 类型)
		{
			if (World.物品记录 == 1)
			{
				string sql = string.Format("INSERT INTO 物品记录 (UserId,UserName,ToUserId,ToUserName,全局ID,物品ID,物品名,物品数量,物品属性,钱数,类型) VALUES (@UserId,@UserName,@ToUserId,@ToUserName,@全局ID,@物品ID,@物品名,@物品数量,@物品属性,@钱数,@类型)", new object[0]);
				SqlParameter[] prams = new SqlParameter[]
				{
					SqlDBA.MakeInParam("@UserId", SqlDbType.VarChar, 30, UserId),
					SqlDBA.MakeInParam("@UserName", SqlDbType.VarChar, 30, UserName),
					SqlDBA.MakeInParam("@ToUserId", SqlDbType.VarChar, 30, ToUserId),
					SqlDBA.MakeInParam("@ToUserName", SqlDbType.VarChar, 30, ToUserName),
					SqlDBA.MakeInParam("@全局ID", SqlDbType.VarChar, 30, 全局ID),
					SqlDBA.MakeInParam("@物品ID", SqlDbType.VarChar, 30, 物品ID),
					SqlDBA.MakeInParam("@物品名", SqlDbType.VarChar, 30, 物品名),
					SqlDBA.MakeInParam("@物品数量", SqlDbType.Int, 4, 物品数量),
					SqlDBA.MakeInParam("@物品属性", SqlDbType.VarChar, 100, 物品属性),
					SqlDBA.MakeInParam("@钱数", SqlDbType.Int, 4, 钱数),
					SqlDBA.MakeInParam("@类型", SqlDbType.VarChar, 10, 类型)
				};
				DbPoolClass dbPoolClass = new DbPoolClass();
				dbPoolClass.Conn = DBA.getstrConnection(null);
				dbPoolClass.Prams = prams;
				dbPoolClass.Sql = sql;
				dbPoolClass.Type = 1;
				World.SqlPool.Enqueue(dbPoolClass);
			}
		}

		public static void 帮战最后奖励(int 帮派ID, int sl)
		{
			if (sl == 1)
			{
				string sqlCommand = string.Format("UPDATE TBL_帮派数据 SET 胜=胜+2 WHERE ID='{0}'", 帮派ID);
				DBA.ExeSqlCommand(sqlCommand);
				return;
			}
			if (sl == -1)
			{
				string sqlCommand2 = string.Format("UPDATE TBL_帮派数据 SET 败=败+1,胜=胜+1 WHERE ID='{0}'", 帮派ID);
				DBA.ExeSqlCommand(sqlCommand2);
				return;
			}
			if (sl == 0)
			{
				string sqlCommand3 = string.Format("UPDATE TBL_帮派数据 SET 平=平+1 WHERE ID='{0}'", 帮派ID);
				DBA.ExeSqlCommand(sqlCommand3);
			}
		}

		public static void 申请门徽(int 帮派id, byte[] _门徽)
		{
			string sqlCommand = string.Format("UPDATE TBL_帮派数据 SET 门徽={1} WHERE ID='{0}'", 帮派id, Converter.ToString1(_门徽));
			DBA.ExeSqlCommand(sqlCommand);
		}

		public static byte[] 得到门徽(int id)
		{
			byte[] result;
			try
			{
				string sqlCommand = string.Format("SELECT * FROM TBL_帮派数据 WHERE ID = {0}", id);
				DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand);
				if (dBToDataTable.Rows.Count == 0)
				{
					result = null;
				}
				else if (dBToDataTable.Rows[0]["门徽"].GetType().ToString() == "System.DBNull")
				{
					result = null;
				}
				else
				{
					byte[] array = (byte[])dBToDataTable.Rows[0]["门徽"];
					if (array != null)
					{
						result = array;
					}
					else
					{
						result = null;
					}
				}
			}
			catch (Exception value)
			{
				Console.WriteLine(value);
				result = null;
			}
			return result;
		}

		public static void PK记录(string UserId, string UserName, string ToUserId, string ToUserName)
		{
			if (World.PK记录 == 1)
			{
				string sql = string.Format("INSERT INTO TBL_PK记录 (UserId,UserName,ToUserId,ToUserName) VALUES (@UserId,@UserName,@ToUserId,@ToUserName)", new object[0]);
				SqlParameter[] prams = new SqlParameter[]
				{
					SqlDBA.MakeInParam("@UserId", SqlDbType.VarChar, 30, UserId),
					SqlDBA.MakeInParam("@UserName", SqlDbType.VarChar, 30, UserName),
					SqlDBA.MakeInParam("@ToUserId", SqlDbType.VarChar, 30, ToUserId),
					SqlDBA.MakeInParam("@ToUserName", SqlDbType.VarChar, 30, ToUserName)
				};
				DbPoolClass dbPoolClass = new DbPoolClass();
				dbPoolClass.Conn = DBA.getstrConnection(null);
				dbPoolClass.Prams = prams;
				dbPoolClass.Sql = sql;
				dbPoolClass.Type = 1;
				World.SqlPool.Enqueue(dbPoolClass);
			}
		}

		public static bool 删除人物记录(string UserId, string UserName, string UserIp)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(0, "PlayersBes_删除人物数据存储过程()");
			}
			try
			{
				string sqlCommand = string.Format("EXEC DELETE_USER_DATA @id, @name, @cip", new object[0]);
				SqlParameter[] prams = new SqlParameter[]
				{
					SqlDBA.MakeInParam("@id", SqlDbType.VarChar, 20, UserId),
					SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 20, UserName),
					SqlDBA.MakeInParam("@cip", SqlDbType.VarChar, 20, UserIp)
				};
				if (DBA.ExeSqlCommand(sqlCommand, prams) != -1)
				{
					return true;
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, string.Concat(new string[]
				{
					"删除人物数据存储过程出错[",
					UserId,
					"]-[",
					UserName,
					"]",
					ex.Message
				}));
			}
			return false;
		}

		public static DataTable 得到传书列表(string name)
		{
			string sqlCommand = string.Format("SELECT top 10 * FROM TBL_传书系统 WHERE 接收人物名 =@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static int 删除传书列表(string name)
		{
			try
			{
				string sqlCommand = string.Format("delete [TBL_传书系统] WHERE 接收人物名 ='{0}'", name);
				if (DBA.ExeSqlCommand(sqlCommand, "GameServer") != -1)
				{
					return 1;
				}
			}
			catch
			{
			}
			return -1;
		}

		public static void 设置传书已读(int id, int 是否已读)
		{
			string sqlCommand = string.Format("UPDATE TBL_传书系统 SET 阅读标识=@rd WHERE ID=@id", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@rd", SqlDbType.Int, 0, 是否已读),
				SqlDBA.MakeInParam("@id", SqlDbType.Int, 30, id)
			};
			DBA.ExeSqlCommand(sqlCommand, prams);
		}

		public static void 创建传书(string fname, string sname, int npcid, string msg)
		{
			string sqlCommand = string.Format("EXEC INT_CS_DATA_New @fname, @sname, @msg, @npcid", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@fname", SqlDbType.VarChar, 30, fname),
				SqlDBA.MakeInParam("@sname", SqlDbType.VarChar, 30, sname),
				SqlDBA.MakeInParam("@msg", SqlDbType.VarChar, 2000, msg),
				SqlDBA.MakeInParam("@npcid", SqlDbType.Int, 0, npcid)
			};
			DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static void 帮派赋予职位(int zw, string name)
		{
			string sqlCommand = string.Format("UPDATE TBL_帮派成员 SET Leve=@zw WHERE Name=@Username", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@zw", SqlDbType.Int, 0, zw),
				SqlDBA.MakeInParam("@Username", SqlDbType.VarChar, 30, name)
			};
			DBA.ExeSqlCommand(sqlCommand, prams);
		}

		public static int 清除领奖标记()
		{
			string sqlCommand = string.Format("EXEC UPDATE_LQBZ", new object[0]);
			return (int)DBA.GetDBValue_3(sqlCommand);
		}

		public static int 创建帮派确认(string 帮派name)
		{
			string sqlCommand = string.Format("EXEC SELECT_Guild_DATA @bpnamea", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@bpnamea", SqlDbType.VarChar, 30, 帮派name)
			};
			return (int)DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static int 创建帮派(string name, string 帮派name, int leve)
		{
			string sqlCommand = string.Format("EXEC INT_Guild_DATA_New @name, @bpname,@leve", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name),
				SqlDBA.MakeInParam("@bpname", SqlDbType.VarChar, 30, 帮派name),
				SqlDBA.MakeInParam("@leve", SqlDbType.Int, 0, leve)
			};
			return (int)DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static int 加入帮派(string name, string 帮派name, int leve)
		{
			string sqlCommand = string.Format("EXEC JR_Guild_DATA_New @name, @bpname,@leve", name, 帮派name, leve);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name),
				SqlDBA.MakeInParam("@bpname", SqlDbType.VarChar, 30, 帮派name),
				SqlDBA.MakeInParam("@leve", SqlDbType.Int, 0, leve)
			};
			return (int)DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static int 退出门派(string name)
		{
			string sqlCommand = string.Format("EXEC Out_Guild_DATA @name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			return (int)DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static int 逐出门派(string name, string 帮派name)
		{
			string sqlCommand = string.Format("EXEC OutBz_Guild_DATA @name, @bpname", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name),
				SqlDBA.MakeInParam("@bpname", SqlDbType.VarChar, 30, 帮派name)
			};
			return (int)DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static int GetUserName(string name)
		{
			string sqlCommand = string.Format("SELECT FLD_NAME FROM TBL_人物数据 WHERE FLD_NAME=@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return -1;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				dBToDataTable.Dispose();
				return 1;
			}
			dBToDataTable.Dispose();
			return -1;
		}

		public static int CheckUserName(string name)
		{
			string sqlCommand = string.Format("SELECT FLD_NAME FROM TBL_人物数据 WHERE FLD_NAME=@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return -1;
			}
			if (dBToDataTable.Rows.Count == 1)
			{
				dBToDataTable.Dispose();
				return 1;
			}
			dBToDataTable.Dispose();
			return -1;
		}

		public static DataTable 得到帮派人数(string name)
		{
			string sqlCommand = string.Format("SELECT * FROM TBL_帮派成员 WHERE G_Name =@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static DataTable 得到帮派数据(string name)
		{
			string sqlCommand = string.Format("SELECT * FROM TBL_帮派数据 WHERE G_Name = @name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static DataTable GetUserNameBp(string name)
		{
			string sqlCommand = string.Format("EXEC LOAD_Guild @name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static DataTable GetUserWarehouse(string Userid, string Username)
		{
			string sqlCommand = string.Format("select * from [TBL_个人仓库] where FLD_ID=@Userid and FLD_NAME =@Username", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid),
				SqlDBA.MakeInParam("@Username", SqlDbType.VarChar, 30, Username)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count != 0)
			{
				return dBToDataTable;
			}
			string sqlCommand2 = string.Format("EXEC CREATE_USER_BANK @Userid,@Username,@aa,@zb", new object[0]);
			SqlParameter[] prams2 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid),
				SqlDBA.MakeInParam("@Username", SqlDbType.VarChar, 30, Username),
				SqlDBA.MakeInParam("@aa", SqlDbType.Int, 0, 0),
				SqlDBA.MakeInParam("@zb", SqlDbType.VarBinary, 4380, new byte[4380])
			};
			DBA.ExeSqlCommand(sqlCommand2, prams2);
			string sqlCommand3 = string.Format("select * from [TBL_个人仓库] where FLD_ID=@Userid and FLD_NAME =@Username", new object[0]);
			SqlParameter[] prams3 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid),
				SqlDBA.MakeInParam("@Username", SqlDbType.VarChar, 30, Username)
			};
			DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand3, prams3);
			if (dBToDataTable2 == null)
			{
				return null;
			}
			if (dBToDataTable2.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable2;
		}

		public static DataTable GetUserPublicWarehouse(string Userid)
		{
			string sqlCommand = string.Format("select * from [TBL_综合仓库] where FLD_ID=@Userid", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count != 0)
			{
				return dBToDataTable;
			}
			Converter.ToString1(new byte[4380]);
			Converter.ToString1(new byte[50]);
			string sqlCommand2 = string.Format("EXEC CREATE_ID_BANK @Userid,@aaa,@ck,@ck1", new object[0]);
			SqlParameter[] prams2 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid),
				SqlDBA.MakeInParam("@aaa", SqlDbType.Int, 0, 0),
				SqlDBA.MakeInParam("@ck", SqlDbType.VarBinary, 4380, new byte[4380]),
				SqlDBA.MakeInParam("@ck1", SqlDbType.VarBinary, 50, new byte[50])
			};
			DBA.ExeSqlCommand(sqlCommand2, prams2);
			string sqlCommand3 = string.Format("select * from [TBL_综合仓库] where FLD_ID='{0}'", Userid);
			SqlParameter[] prams3 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid)
			};
			DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand3, prams3);
			if (dBToDataTable2 == null)
			{
				return null;
			}
			if (dBToDataTable2.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable2;
		}

		public static int SetUserName(string id, string name, int zy, byte[] coue, int xb)
		{
			byte[] array = new byte[73];
			byte[] array2 = new byte[1095];
			byte[] array3 = new byte[2628];
			byte[] bytes = BitConverter.GetBytes(RxjhClass.GetDBItmeId());
			byte[] src = new byte[4];
			byte[] src2 = new byte[4];
			src2 = BitConverter.GetBytes(1);
			switch (zy)
			{
			case 1:
				src = BitConverter.GetBytes(100200002);
				break;
			case 2:
				src = BitConverter.GetBytes(200200002);
				break;
			case 3:
				src = BitConverter.GetBytes(300200002);
				break;
			case 4:
				src = BitConverter.GetBytes(400200002);
				break;
			case 5:
				src = BitConverter.GetBytes(500200002);
				break;
			}
			Buffer.BlockCopy(bytes, 0, array, 0, 4);
			Buffer.BlockCopy(src, 0, array, 8, 4);
			Buffer.BlockCopy(src2, 0, array, 12, 4);
			Buffer.BlockCopy(array, 0, array3, 0, 73);
			int num = 0;
			for (int i = 0; i < 4; i++)
			{
				string sqlCommand = string.Format("Select FLD_INDEX FROM TBL_人物数据 Where FLD_ID=@FLD_ID and FLD_INDEX=@INDEX", new object[0]);
				SqlParameter[] prams = new SqlParameter[]
				{
					SqlDBA.MakeInParam("@INDEX", SqlDbType.Int, 0, i),
					SqlDBA.MakeInParam("@FLD_ID", SqlDbType.VarChar, 30, id)
				};
				DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
				if (dBToDataTable.Rows.Count == 0)
				{
					num = i;
					dBToDataTable.Dispose();
					break;
				}
				dBToDataTable.Dispose();
			}
			string sqlCommand2 = string.Format("Select FLD_INDEX FROM TBL_人物数据 Where FLD_ID=@FLD_ID", new object[0]);
			SqlParameter[] prams2 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@FLD_ID", SqlDbType.VarChar, 30, id)
			};
			DataTable dBToDataTable2 = DBA.GetDBToDataTable(sqlCommand2, prams2);
			if (dBToDataTable2.Rows.Count >= 4)
			{
				dBToDataTable2.Dispose();
				return -1;
			}
			dBToDataTable2.Dispose();
			string sqlCommand3 = string.Format("EXEC INT_USER_DATA @FLD_ID,@name,@rwid,@zy,@xb,@coue,@xrwhex,@xrwhex2", new object[0]);
			SqlParameter[] prams3 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@FLD_ID", SqlDbType.VarChar, 30, id),
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name),
				SqlDBA.MakeInParam("@rwid", SqlDbType.Int, 0, num),
				SqlDBA.MakeInParam("@zy", SqlDbType.Int, 0, zy),
				SqlDBA.MakeInParam("@xb", SqlDbType.Int, 0, xb),
				SqlDBA.MakeInParam("@coue", SqlDbType.VarBinary, 10, coue),
				SqlDBA.MakeInParam("@xrwhex", SqlDbType.VarBinary, array2.Length, array2),
				SqlDBA.MakeInParam("@xrwhex2", SqlDbType.VarBinary, array3.Length, array3)
			};
			if (DBA.ExeSqlCommand(sqlCommand3, prams3) != -1)
			{
				return 1;
			}
			return -1;
		}

		public static int GetCwUserName(string name, string zrname, int type, long id)
		{
			string sqlCommand = string.Format("SELECT Name FROM TBL_宠物数据 WHERE Name=@name", name);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return -1;
			}
			if (dBToDataTable.Rows.Count != 0)
			{
				dBToDataTable.Dispose();
				return -1;
			}
			dBToDataTable.Dispose();
			string sqlCommand2 = string.Format("EXEC INT_Cw_DATA @zrname,@name,@id,@type,@zb1,@zb2", new object[]
			{
				zrname,
				name,
				id,
				type,
				Converter.ToString(new byte[292]),
				Converter.ToString(new byte[1168])
			});
			SqlParameter[] prams2 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@zrname", SqlDbType.VarChar, 30, zrname),
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name),
				SqlDBA.MakeInParam("@id", SqlDbType.Int, 0, id),
				SqlDBA.MakeInParam("@type", SqlDbType.Int, 0, type),
				SqlDBA.MakeInParam("@zb1", SqlDbType.VarBinary, 292, new byte[292]),
				SqlDBA.MakeInParam("@zb2", SqlDbType.VarBinary, 1168, new byte[1168])
			};
			if (DBA.ExeSqlCommand(sqlCommand2, prams2) != -1)
			{
				return 1;
			}
			return -1;
		}

		public static bool 增加元宝(string id, int point)
		{
			if (DBA.GetDBToDataTable(string.Format("select * from [TBL_ACCOUNT] where FLD_ID='{0}'", id), "rxjhaccount") == null)
			{
				return false;
			}
			string sqlCommand = string.Format("update [TBL_ACCOUNT] SET FLD_RXPIONT=FLD_RXPIONT + '{1}' WHERE FLD_ID ='{0}'", id, point);
			return DBA.ExeSqlCommand(sqlCommand, "rxjhaccount") != -1;
		}

		public static int GetCwDead(long id)
		{
			int result = 0;
			string sqlCommand = string.Format("SELECT FLD_SW FROM TBL_宠物数据 WHERE Itmeid=@id", id);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@id", SqlDbType.Int, 30, id)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable != null)
			{
				if (dBToDataTable.Rows.Count != 0)
				{
					result = (int)dBToDataTable.Rows[0]["FLD_SW"];
					dBToDataTable.Dispose();
				}
				else
				{
					dBToDataTable.Dispose();
				}
			}
			return result;
		}

		public static int GetCwJobLevel(long id)
		{
			int result = 0;
			string sqlCommand = string.Format("SELECT FLD_JOB_LEVEL FROM TBL_宠物数据 WHERE Itmeid=@id", id);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@id", SqlDbType.Int, 30, id)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable != null)
			{
				if (dBToDataTable.Rows.Count != 0)
				{
					result = (int)dBToDataTable.Rows[0]["FLD_JOB_LEVEL"];
					dBToDataTable.Dispose();
				}
				else
				{
					dBToDataTable.Dispose();
				}
			}
			return result;
		}

		public static bool SetCwDead(long id)
		{
			string sqlCommand = string.Format("UPDATE TBL_宠物数据 SET FLD_SW=0,FLD_HP=100 WHERE Itmeid={0}", id);
			return DBA.ExeSqlCommand(sqlCommand, "GameServer") != -1;
		}

		public static DataTable 得到师傅数据(string name)
		{
			string sqlCommand = string.Format("SELECT * FROM TBL_师徒数据 WHERE FLD_TNAME =@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static DataTable 得到徒弟数据(string name)
		{
			string sqlCommand = string.Format("SELECT * FROM TBL_师徒数据 WHERE FLD_SNAME =@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, name)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static int 创建师徒关系(string 徒弟, string 师傅, int tlevel, int index)
		{
			string sqlCommand = string.Format("SELECT FLD_TNAME FROM TBL_师徒数据 WHERE FLD_TNAME=@name", 徒弟);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.VarChar, 30, 徒弟)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return -1;
			}
			if (dBToDataTable.Rows.Count != 0)
			{
				dBToDataTable.Dispose();
				return -1;
			}
			dBToDataTable.Dispose();
			string sqlCommand2 = string.Format("EXEC INT_St_DATA @sname,@tname,@tlevel,@index", new object[]
			{
				师傅,
				徒弟,
				tlevel,
				index
			});
			SqlParameter[] prams2 = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@sname", SqlDbType.VarChar, 30, 师傅),
				SqlDBA.MakeInParam("@tname", SqlDbType.VarChar, 30, 徒弟),
				SqlDBA.MakeInParam("@tlevel", SqlDbType.Int, 0, tlevel),
				SqlDBA.MakeInParam("@index", SqlDbType.Int, 0, index)
			};
			if (DBA.ExeSqlCommand(sqlCommand2, prams2) != -1)
			{
				return 1;
			}
			return -1;
		}

		public static int 解除师徒关系(string 徒弟, string 师傅)
		{
			string sqlCommand = string.Format("delete [TBL_师徒数据] WHERE FLD_TNAME ='{0}' and FLD_SNAME='{1}'", 徒弟, 师傅);
			if (DBA.ExeSqlCommand(sqlCommand, "GameServer") != -1)
			{
				return 1;
			}
			return -1;
		}

		public static int 换名符确认(string Userid, string UserName, string sTemp)
		{
			string sqlCommand = string.Format("EXEC PROC_USER_RENAME @Userid,@Username,@sTemp", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@Userid", SqlDbType.VarChar, 30, Userid),
				SqlDBA.MakeInParam("@Username", SqlDbType.VarChar, 30, UserName),
				SqlDBA.MakeInParam("@sTemp", SqlDbType.VarChar, 30, sTemp)
			};
			return (int)DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static void 初始化副本次数()
		{
			string sqlCommand = string.Format("EXEC INT_FB_DATA_New", new object[0]);
			SqlParameter[] prams = null;
			DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static void 初始化BOSS次数()
		{
			string sqlCommand = string.Format("EXEC INT_BOSS_DATA_New", new object[0]);
			SqlParameter[] prams = null;
			DBA.GetDBValue_3(sqlCommand, prams);
		}

		public static DataTable 得到宠物数据(long itemid)
		{
			string sqlCommand = string.Format("SELECT * FROM TBL_宠物数据 WHERE ItmeId =@name", new object[0]);
			SqlParameter[] prams = new SqlParameter[]
			{
				SqlDBA.MakeInParam("@name", SqlDbType.BigInt, 0, itemid)
			};
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, prams);
			if (dBToDataTable == null)
			{
				return null;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				return null;
			}
			return dBToDataTable;
		}

		public static int 寄售元宝(string UserId, int 元宝数)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("UPDATE [TBL_ACCOUNT] SET FLD_RXPIONT = FLD_RXPIONT + {1} WHERE FLD_ID = '{0}'", UserId, 元宝数);
			return DBA.ExeSqlCommand(stringBuilder.ToString(), "rxjhaccount");
		}

		public static int 寄售物品(寄存物品类 物品)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("INSERT INTO PLAYITEM (FLD_PID,FLD_NAME,FLD_PRICE,FLD_DESC,FLD_TYPE,FLD_MAGIC0,FLD_MAGIC1,FLD_MAGIC2,FLD_MAGIC3,FLD_MAGIC4,FLD_绑定,FLD_PlayID,FLD_PlayName,ID) VALUES ({0},'{1}',{2},'{3}',{4},{5},{6},{7},{8},{9},{10},'{11}','{12}',{13})", new object[]
			{
				物品.PID,
				物品.NAME,
				物品.PRICE,
				物品.DESC,
				物品.TYPE,
				物品.MAGIC0,
				物品.MAGIC1,
				物品.MAGIC2,
				物品.MAGIC3,
				物品.MAGIC4,
				物品.绑定,
				物品.PlayID,
				物品.PlayName,
				物品.ID
			});
			return DBA.ExeSqlCommand(stringBuilder.ToString(), "bbgDb");
		}

		public static int 取消寄售(long id)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("DELETE PLAYITEM WHERE ID = {0}", id);
			return DBA.ExeSqlCommand(stringBuilder.ToString(), "bbgDb");
		}

		public static int 变更寄售类型(int id, int lx)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("UPDATE PLAYITEM SET FLD_TYPE = {1} WHERE ID = {0}", id, lx);
			return DBA.ExeSqlCommand(stringBuilder.ToString(), "bbgDb");
		}

		public static int 变更寄售时间(int id)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("UPDATE PLAYITEM SET FLD_TIME = '{1}' WHERE ID = {0}", id, DateTime.Now);
			return DBA.ExeSqlCommand(stringBuilder.ToString(), "bbgDb");
		}

		public static int 得到寄售Key()
		{
			string sqlCommand = "Select TOP 1 * from [PLAYITEM] Order By ID";
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, "bbgDb");
			if (dBToDataTable != null)
			{
				return (int)dBToDataTable.Rows[0]["ID"];
			}
			return 0;
		}

		public static int 得到寄售数量(string id)
		{
			string sqlCommand = string.Format("Select * from [PLAYITEM] where FLD_TYPE = 1 AND FLD_PLAYID = '{0}' ", id);
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, "bbgDb");
			if (dBToDataTable != null)
			{
				return dBToDataTable.Rows.Count;
			}
			return 0;
		}

		public static 寄存物品类 得到寄售物品(int 全局ID)
		{
			try
			{
				string sqlCommand = string.Format("Select * from [PLAYITEM] where FLD_TYPE = 1 AND ID = {0}", 全局ID);
				DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, "bbgDb");
				if (dBToDataTable != null)
				{
					if (dBToDataTable.Rows.Count == 0)
					{
						dBToDataTable.Dispose();
					}
					else
					{
						if (dBToDataTable.Rows.Count <= 1)
						{
							寄存物品类 寄存物品类 = new 寄存物品类();
							寄存物品类.ID = (long)dBToDataTable.Rows[0]["ID"];
							寄存物品类.PID = (int)dBToDataTable.Rows[0]["FLD_PID"];
							寄存物品类.NAME = dBToDataTable.Rows[0]["FLD_NAME"].ToString();
							寄存物品类.PRICE = (int)dBToDataTable.Rows[0]["FLD_PRICE"];
							寄存物品类.DESC = dBToDataTable.Rows[0]["FLD_DESC"].ToString();
							寄存物品类.TYPE = (int)dBToDataTable.Rows[0]["FLD_TYPE"];
							寄存物品类.MAGIC0 = (int)dBToDataTable.Rows[0]["FLD_MAGIC0"];
							寄存物品类.MAGIC1 = (int)dBToDataTable.Rows[0]["FLD_MAGIC1"];
							寄存物品类.MAGIC2 = (int)dBToDataTable.Rows[0]["FLD_MAGIC2"];
							寄存物品类.MAGIC3 = (int)dBToDataTable.Rows[0]["FLD_MAGIC3"];
							寄存物品类.MAGIC4 = (int)dBToDataTable.Rows[0]["FLD_MAGIC4"];
							寄存物品类.绑定 = (int)dBToDataTable.Rows[0]["FLD_绑定"];
							寄存物品类.PlayID = dBToDataTable.Rows[0]["FLD_PlayID"].ToString();
							寄存物品类.PlayName = dBToDataTable.Rows[0]["FLD_PlayName"].ToString();
							寄存物品类.时间 = DateTime.Parse(dBToDataTable.Rows[0]["FLD_TIME"].ToString());
							dBToDataTable.Dispose();
							return 寄存物品类;
						}
						int num = (int)dBToDataTable.Rows[0]["ID"];
						logo.寄售记录("得到寄售物品()出错 存在重复全局ID - " + num);
						dBToDataTable.Dispose();
					}
				}
			}
			catch (Exception ex)
			{
				string arg_29B_0 = ex.Message;
			}
			return null;
		}
	}
}
